package org.example.controller.admin;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.example.entity.Gowuche;
import org.example.entity.Shanpin;
import org.example.mapper.Shouchanmapper;
import org.example.result.Result;
import org.example.service.GowucheService;
import org.example.service.ShouchanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/gowuche")
@Slf4j
@Api(tags = "购物车相关接口")
public class EmployeegowucheController {
    @Autowired
    GowucheService gowucheService;

    @Autowired
    ShouchanService shouchanService;
    /**
     * 购物车新增
     * @param gowuche
     * @return
     */
    @PostMapping("/xz")
    @ApiOperation(value = "购物车新增")
    public Result processPayment(@RequestBody Gowuche gowuche) {
        log.info("购物车新增：{}",gowuche);
        gowucheService.xz(gowuche);
        return Result.success();
    }


    /**
     * 购物车查询
     * @param
     * @return
     */
    @GetMapping("/cx")
    @ApiOperation(value = "购物车查询")
    public Result<List<Gowuche>> gwccx(@RequestParam( "username") String username) {
        log.info("购物车查询：{}", username);
        return Result.success(  gowucheService.cx(username) );
    }


    /**
     * 购物车删除
     * @param
     * @return
     */
    @DeleteMapping("/sc")
    @ApiOperation(value = "购物车删除")
    public Result gwcsc(@RequestParam( "id") int id) {
        log.info("购物车删除：{}", id);
        gowucheService.sc(id);
        return Result.success( );
    }



    /**
     * 商品移入收藏
     *
     * @param
     * @return
     */
    @PostMapping("/yr")
    @ApiOperation(value = "商品移入收藏")
    public Result yr(@RequestParam("id") int id,
                     @RequestParam("username") String username) {
        log.info("商品收藏修改：{}", id);
        shouchanService.xz(id,username);
        return Result.success();

    }


}
